#include <Carbon/Carbon.h> // For keycodes
#include "aw.h"

unsigned mapkeycode(unsigned k) {
	unsigned ret;
	switch (k) {
	case kVK_ANSI_A: ret = AW_KEY_A; break;
	case kVK_ANSI_S: ret = AW_KEY_S; break;
	case kVK_ANSI_D: ret = AW_KEY_D; break;
	case kVK_ANSI_F: ret = AW_KEY_F; break;
	case kVK_ANSI_H: ret = AW_KEY_H; break;
	case kVK_ANSI_G: ret = AW_KEY_G; break;
	case kVK_ANSI_Z: ret = AW_KEY_Z; break;
	case kVK_ANSI_X: ret = AW_KEY_X; break;
	case kVK_ANSI_C: ret = AW_KEY_C; break;
	case kVK_ANSI_V: ret = AW_KEY_V; break;
	case kVK_ANSI_B: ret = AW_KEY_B; break;
	case kVK_ANSI_Q: ret = AW_KEY_Q; break;
	case kVK_ANSI_W: ret = AW_KEY_W; break;
	case kVK_ANSI_E: ret = AW_KEY_E; break;
	case kVK_ANSI_R: ret = AW_KEY_R; break;
	case kVK_ANSI_Y: ret = AW_KEY_Y; break;
	case kVK_ANSI_T: ret = AW_KEY_T; break;
	case kVK_ANSI_1: ret = AW_KEY_1; break;
	case kVK_ANSI_2: ret = AW_KEY_2; break;
	case kVK_ANSI_3: ret = AW_KEY_3; break;
	case kVK_ANSI_4: ret = AW_KEY_4; break;
	case kVK_ANSI_6: ret = AW_KEY_6; break;
	case kVK_ANSI_5: ret = AW_KEY_5; break;
	case kVK_ANSI_Equal: ret = AW_KEY_EQUAL; break;
	case kVK_ANSI_9: ret = AW_KEY_9; break;
	case kVK_ANSI_7: ret = AW_KEY_7; break;
	case kVK_ANSI_Minus: ret = AW_KEY_MINUS; break;
	case kVK_ANSI_8: ret = AW_KEY_8; break;
	case kVK_ANSI_0: ret = AW_KEY_0; break;
	case kVK_ANSI_RightBracket: ret = AW_KEY_RIGHTBRACKET; break;
	case kVK_ANSI_O: ret = AW_KEY_O; break;
	case kVK_ANSI_U: ret = AW_KEY_U; break;
	case kVK_ANSI_LeftBracket: ret = AW_KEY_LEFTBRACKET; break;
	case kVK_ANSI_I: ret = AW_KEY_I; break;
	case kVK_ANSI_P: ret = AW_KEY_P; break;
	case kVK_ANSI_L: ret = AW_KEY_L; break;
	case kVK_ANSI_J: ret = AW_KEY_J; break;
	case kVK_ANSI_Quote: ret = AW_KEY_QUOTE; break;
	case kVK_ANSI_K: ret = AW_KEY_K; break;
	case kVK_ANSI_Semicolon: ret = AW_KEY_SEMICOLON; break;
	case kVK_ANSI_Backslash: ret = AW_KEY_BACKSLASH; break;
	case kVK_ANSI_Comma: ret = AW_KEY_COMMA; break;
	case kVK_ANSI_Slash: ret = AW_KEY_SLASH; break;
	case kVK_ANSI_N: ret = AW_KEY_N; break;
	case kVK_ANSI_M: ret = AW_KEY_M; break;
	case kVK_ANSI_Period: ret = AW_KEY_PERIOD; break;
	case kVK_ANSI_Grave: ret = AW_KEY_GRAVE; break;
	case kVK_ANSI_KeypadDecimal: ret = AW_KEY_KEYPADDECIMAL; break;
	case kVK_ANSI_KeypadMultiply: ret = AW_KEY_KEYPADMULTIPLY; break;
	case kVK_ANSI_KeypadPlus: ret = AW_KEY_KEYPADPLUS; break;
	case kVK_ANSI_KeypadClear: ret = AW_KEY_KEYPADCLEAR; break;
	case kVK_ANSI_KeypadDivide: ret = AW_KEY_KEYPADDIVIDE; break;
	case kVK_ANSI_KeypadEnter: ret = AW_KEY_KEYPADENTER; break;
	case kVK_ANSI_KeypadMinus: ret = AW_KEY_KEYPADMINUS; break;
	case kVK_ANSI_KeypadEquals: ret = AW_KEY_KEYPADEQUALS; break;
	case kVK_ANSI_Keypad0: ret = AW_KEY_KEYPAD0; break;
	case kVK_ANSI_Keypad1: ret = AW_KEY_KEYPAD1; break;
	case kVK_ANSI_Keypad2: ret = AW_KEY_KEYPAD2; break;
	case kVK_ANSI_Keypad3: ret = AW_KEY_KEYPAD3; break;
	case kVK_ANSI_Keypad4: ret = AW_KEY_KEYPAD4; break;
	case kVK_ANSI_Keypad5: ret = AW_KEY_KEYPAD5; break;
	case kVK_ANSI_Keypad6: ret = AW_KEY_KEYPAD6; break;
	case kVK_ANSI_Keypad7: ret = AW_KEY_KEYPAD7; break;
	case kVK_ANSI_Keypad8: ret = AW_KEY_KEYPAD8; break;
	case kVK_ANSI_Keypad9: ret = AW_KEY_KEYPAD9; break;
	case kVK_Return: ret = AW_KEY_RETURN; break;
	case kVK_Tab: ret = AW_KEY_TAB; break;
	case kVK_Space: ret = AW_KEY_SPACE; break;
	case kVK_Delete: ret = AW_KEY_DELETE; break;
	case kVK_Escape: ret = AW_KEY_ESCAPE; break;
	case kVK_Command: ret = AW_KEY_COMMAND; break;
	case kVK_Shift: ret = AW_KEY_SHIFT; break;
	case kVK_CapsLock: ret = AW_KEY_CAPSLOCK; break;
	case kVK_Option: ret = AW_KEY_OPTION; break;
	case kVK_Control: ret = AW_KEY_CONTROL; break;
	case kVK_RightShift: ret = AW_KEY_RIGHTSHIFT; break;
	case kVK_RightOption: ret = AW_KEY_RIGHTOPTION; break;
	case kVK_RightControl: ret = AW_KEY_RIGHTCONTROL; break;
	case kVK_Function: ret = AW_KEY_FUNCTION; break;
	case kVK_F17: ret = AW_KEY_F17; break;
	case kVK_VolumeUp: ret = AW_KEY_VOLUMEUP; break;
	case kVK_VolumeDown: ret = AW_KEY_VOLUMEDOWN; break;
	case kVK_Mute: ret = AW_KEY_MUTE; break;
	case kVK_F18: ret = AW_KEY_F18; break;
	case kVK_F19: ret = AW_KEY_F19; break;
	case kVK_F20: ret = AW_KEY_F20; break;
	case kVK_F5: ret = AW_KEY_F5; break;
	case kVK_F6: ret = AW_KEY_F6; break;
	case kVK_F7: ret = AW_KEY_F7; break;
	case kVK_F3: ret = AW_KEY_F3; break;
	case kVK_F8: ret = AW_KEY_F8; break;
	case kVK_F9: ret = AW_KEY_F9; break;
	case kVK_F11: ret = AW_KEY_F11; break;
	case kVK_F13: ret = AW_KEY_F13; break;
	case kVK_F16: ret = AW_KEY_F16; break;
	case kVK_F14: ret = AW_KEY_F14; break;
	case kVK_F10: ret = AW_KEY_F10; break;
	case kVK_F12: ret = AW_KEY_F12; break;
	case kVK_F15: ret = AW_KEY_F15; break;
	case kVK_Help: ret = AW_KEY_HELP; break;
	case kVK_Home: ret = AW_KEY_HOME; break;
	case kVK_PageUp: ret = AW_KEY_PAGEUP; break;
	case kVK_ForwardDelete: ret = AW_KEY_FORWARDDELETE; break;
	case kVK_F4: ret = AW_KEY_F4; break;
	case kVK_End: ret = AW_KEY_END; break;
	case kVK_F2: ret = AW_KEY_F2; break;
	case kVK_PageDown: ret = AW_KEY_PAGEDOWN; break;
	case kVK_F1: ret = AW_KEY_F1; break;
	case kVK_LeftArrow: ret = AW_KEY_LEFTARROW; break;
	case kVK_RightArrow: ret = AW_KEY_RIGHTARROW; break;
	case kVK_DownArrow: ret = AW_KEY_DOWNARROW; break;
	case kVK_UpArrow: ret = AW_KEY_UPARROW; break;
	default: ret = AW_KEY_NONE;
	}
	return ret;
}

